package com.dimples.dd.system.mapper;

import com.dimples.dd.common.pojo.PageResult;
import com.dimples.dd.mybatis.core.mapper.BaseMapperX;
import com.dimples.dd.mybatis.core.query.LambdaQueryWrapperX;
import com.dimples.dd.system.model.entity.SystemSmsLogDO;
import com.dimples.dd.system.model.query.SmsLogPageQuery;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface SystemSmsLogMapper extends BaseMapperX<SystemSmsLogDO> {

    /**
     * 分页查询短信日志
     *
     * @param pageQuery 查询参数
     * @return PageResult
     */
    default PageResult<SystemSmsLogDO> selectPage(SmsLogPageQuery pageQuery) {
        return selectPage(pageQuery, new LambdaQueryWrapperX<SystemSmsLogDO>()
                .eqIfPresent(SystemSmsLogDO::getChannelId, pageQuery.getChannelId())
                .eqIfPresent(SystemSmsLogDO::getTemplateId, pageQuery.getTemplateId())
                .likeIfPresent(SystemSmsLogDO::getMobile, pageQuery.getMobile())
                .eqIfPresent(SystemSmsLogDO::getSendStatus, pageQuery.getSendStatus())
                .betweenIfPresent(SystemSmsLogDO::getSendTime, pageQuery.getSendTime())
                .eqIfPresent(SystemSmsLogDO::getReceiveStatus, pageQuery.getReceiveStatus())
                .betweenIfPresent(SystemSmsLogDO::getReceiveTime, pageQuery.getReceiveTime())
                .orderByDesc(SystemSmsLogDO::getId));
    }
}